using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using WMSSystem.DYB.Interface;
using WMSSystem.DYB.Dto.Inboundmanagement.Input;
using WMSSystem.DYB.Dto.Inboundmanagement.Output;
using WMSSystem.Application.Contracts;

namespace WMSSystem.HttpApi.Controllers
{
    /// <summary>
    /// 入库审批控制器
    /// </summary>
    [Route("api/inbound-approval")]
    public class InboundApprovalController : AbpController
    {
        private readonly IInboundmanagementService _inboundmanagementService;

        public InboundApprovalController(IInboundmanagementService inboundmanagementService)
        {
            _inboundmanagementService = inboundmanagementService;
        }

        /// <summary>
        /// 审批入库单
        /// </summary>
        /// <param name="input">审批输入</param>
        /// <returns>审批结果</returns>
        [HttpPost("approve")]
        public async Task<ApiResponse<bool>> ApproveInbound([FromBody] ApproveInboundInput input)
        {
            return await _inboundmanagementService.ApproveInbound(input);
        }

        /// <summary>
        /// 获取待审批的入库单列表
        /// </summary>
        /// <returns>待审批列表</returns>
        [HttpGet("pending")]
        public async Task<ApiResponse<List<GetInboundListOutput>>> GetPendingApprovalInboundList()
        {
            // 使用当前登录用户ID
            return await _inboundmanagementService.GetPendingApprovalInboundList(CurrentUser.Id.Value);
        }

        /// <summary>
        /// 审批入库单（简化接口）
        /// </summary>
        /// <param name="inboundId">入库单ID</param>
        /// <param name="approved">是否通过</param>
        /// <param name="comment">审批意见</param>
        /// <returns>审批结果</returns>
        [HttpPost("approve-simple")]
        public async Task<ApiResponse<bool>> ApproveInboundSimple(
            [FromQuery] Guid inboundId,
            [FromQuery] bool approved,
            [FromQuery] string? comment = null)
        {
            var input = new ApproveInboundInput
            {
                InboundId = inboundId,
                ApprovalResult = approved ? "Approved" : "Rejected",
                ApprovalComment = comment
            };

            return await _inboundmanagementService.ApproveInbound(input);
        }
    }
} 